package com.mofang.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;

import com.mofang.R;
import com.mofang.activity.housesource.HouseSourceActivity;
import com.mofang.activity.interact.MainInteractionActivity;
import com.mofang.activity.notice.SystemNoticeActivity;
import com.mofang.activity.recommend.MainRecommendActivity;
import com.mofang.activity.study.MainStudyActivity;
import com.mofang.activity.user.UserCenterActivity;

public class MyTabHostActivity extends TabActivity {

	private Boolean isAdmin = false;

	TabHost myTabHost;

	// user
	public static TabHost mTabHost;

	public static TabHost getmTabHost() {
		return mTabHost;
	}

	private RadioGroup main_tab;
	private RadioButton[] radio_buttons = new RadioButton[6];
	private int[] button_ids = { R.id.radio_button1, R.id.radio_button2,
			R.id.radio_button3, R.id.radio_button4, R.id.radio_button5,
			R.id.radio_button6 };
	private int[] button_selectors = { R.drawable.tabselector_1,
			R.drawable.tabselector_2, R.drawable.tabselector_3,
			R.drawable.tabselector_4, R.drawable.tabselector_5,
			R.drawable.tabselector_6 };
	private TabSpec[] tabSpecs = new TabSpec[6];
	private Class<?>[] classes = { HouseSourceActivity.class,
			MainInteractionActivity.class, MainRecommendActivity.class,
			UserCenterActivity.class, MainStudyActivity.class,
			SystemNoticeActivity.class };
	private RadioButton radio_button1, radio_button2, radio_button3,
			radio_button4, radio_button5;
	private RadioGroup manager_tab;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		if (isAdmin) {

			setContentView(R.layout.manager_tabhost_activity);
			myTabHost = getTabHost();
			final TabWidget tabWidget1 = myTabHost.getTabWidget();
			tabWidget1.setStripEnabled(true);
			myTabHost.addTab(myTabHost
					.newTabSpec("tab1")
					.setIndicator(
							null,
							getResources().getDrawable(
									R.drawable.manager_tabselector_1))
					.setContent(new Intent(this, MainRecommendActivity.class)));

			myTabHost
					.addTab(myTabHost
							.newTabSpec("tab2")
							.setIndicator(
									null,
									getResources().getDrawable(
											R.drawable.manager_tabselector_2))
							.setContent(
									new Intent(this,
											MainInteractionActivity.class)));

			myTabHost.addTab(myTabHost
					.newTabSpec("tab3")
					.setIndicator(
							null,
							getResources().getDrawable(
									R.drawable.manager_tabselector_3))
					.setContent(new Intent(this, UserCenterActivity.class)));

			myTabHost.addTab(myTabHost
					.newTabSpec("tab4")
					.setIndicator(
							null,
							getResources().getDrawable(
									R.drawable.manager_tabselector_4))
					.setContent(new Intent(this, MainRecommendActivity.class)));
			myTabHost.addTab(myTabHost
					.newTabSpec("tab5")
					.setIndicator(
							null,
							getResources().getDrawable(
									R.drawable.manager_tabselector_5))
					.setContent(new Intent(this, MainRecommendActivity.class)));
			manager_tab = (RadioGroup) findViewById(R.id.manager_tab);
			radio_button1 = (RadioButton) findViewById(R.id.manager_radio_button1);
			radio_button2 = (RadioButton) findViewById(R.id.manager_radio_button2);
			radio_button3 = (RadioButton) findViewById(R.id.manager_radio_button3);
			radio_button4 = (RadioButton) findViewById(R.id.manager_radio_button4);
			radio_button5 = (RadioButton) findViewById(R.id.manager_radio_button5);
			manager_tab
					.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

						@Override
						public void onCheckedChanged(RadioGroup group,
								int checkedId) {

							switch (checkedId) {
							case R.id.manager_radio_button1:
								myTabHost.setCurrentTab(0);

								break;
							case R.id.manager_radio_button2:
								myTabHost.setCurrentTab(1);
								break;
							case R.id.manager_radio_button3:
								myTabHost.setCurrentTab(2);

								break;
							case R.id.manager_radio_button4:
								myTabHost.setCurrentTab(3);

								break;
							case R.id.manager_radio_button5:
								myTabHost.setCurrentTab(4);

								break;
							}

						}
					});
			myTabHost.setCurrentTab(0);
			for (int i = 0; i < tabWidget1.getChildCount(); i++) {
				View vi = tabWidget1.getChildAt(i);
			}

			/* ---------------------------------------------------- */
		} else {

			setContentView(R.layout.tabhost_activity);
			myTabHost = getTabHost();
			final TabWidget tabWidget1 = myTabHost.getTabWidget();
			tabWidget1.setStripEnabled(true);
			for (int i = 0; i < 6; i++) {
				tabSpecs[i] = myTabHost
						.newTabSpec("tab1")
						.setIndicator(null,
								getResources().getDrawable(button_selectors[i]))
						.setContent(new Intent(this, classes[i]));
				myTabHost.addTab(tabSpecs[i]);
				radio_buttons[i] = (RadioButton) findViewById(button_ids[i]);
			}
			main_tab = (RadioGroup) findViewById(R.id.main_tab);
			main_tab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(RadioGroup group, int checkedId) {
					switch (checkedId) {
					case R.id.radio_button1:
						myTabHost.setCurrentTab(0);
						break;
					case R.id.radio_button2:
						myTabHost.setCurrentTab(1);
						break;
					case R.id.radio_button3:
						myTabHost.setCurrentTab(2);
						break;
					case R.id.radio_button4:
						myTabHost.setCurrentTab(3);
						break;
					case R.id.radio_button5:
						myTabHost.setCurrentTab(4);
						break;
					case R.id.radio_button6:
						myTabHost.setCurrentTab(5);
						break;
					default:
						break;
					}

				}
			});
			myTabHost.setCurrentTab(0);
			for (int i = 0; i < tabWidget1.getChildCount(); i++) {
				View vi = tabWidget1.getChildAt(i);
			}
		}

	}

}
